package com.bjsxt.common.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.bjsxt.user.pojo.AAdmin;
@Component("myInterceptor")
public class MyInterceptor extends HandlerInterceptorAdapter
{
	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception
	{	
		//handler,是指controller的@Controller注解下的整个方法名
		System.out.println("--------拦截器---------");
		AAdmin admin = (AAdmin)req.getSession().getAttribute("admin");
		if(admin != null )
		{
			System.out.println("通过拦截");
			return true;
		}else
		{
			System.out.println("没有通过拦截");
			req.getSession().setAttribute("info", "请先登录");
			resp.sendRedirect("http://localhost:8080/loan/noLogin/login.htm");
		}
		return false;
	}
	
}
